package com.lkd.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lkd.entity.VendingMachineEntity;
import com.lkd.service.VendingMachineService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class VendingMachineJob {

    //注入VendingMachineService服务，定时执行补货
    @Autowired
    private VendingMachineService vendingMachineService;

    @XxlJob("autoSupply")
    public ReturnT<String> autoSupply(String param){
        XxlJobLogger.log("自动补货任务执行。。。");
        //查询所有的在运营的售货机
        LambdaQueryWrapper<VendingMachineEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(VendingMachineEntity::getVmStatus,1);
        List<VendingMachineEntity> list = vendingMachineService.list(lambdaQueryWrapper);
        //所有的 售货机执行补货业务
        list.forEach(v->{
            vendingMachineService.supplySku(v.getInnerCode());
        });
        return ReturnT.SUCCESS;

    }


}
